/**
 * 格式化时间：刚刚、几小时、几天等等
 * @param {String} str
 * @returns String
 */

 function format(str){
    var d = new Date()
    str = str.replaceAll('Y',d.getFullYear())
    str = str.replaceAll('m',d.getMonth()+1)
    str = str.replaceAll('d',d.getDate())
    str = str.replaceAll('H',d.getHours())
    str = str.replaceAll('i',d.getMinutes())
    str = str.replaceAll('s',d.getSeconds())
    return str
}



/**
 * 格式化时间：返回年月日时分秒格式
 * @param {String} date 年-月-日 时：分：秒
 * @returns String
 */

 function dateFormat(date){
    var oldDate = new Date(date)  //将传进来的字符串转为标准时间
    var newDate = new Date()      //获取本机当前时间
    var minute = 1000 * 60        //每分钟
    var hour = minute * 60        //每小时
    var day = hour * 24           //每天
    var month = day * 30          //每月
    var year = day * 365          //每年
    var dateStr
    var diff = newDate.getTime() - oldDate.getTime()
    if (diff <= minute) {   // 小于一分钟展示为刚刚
        dateStr = '刚刚'
    } else if (minute < diff && diff <= hour) {         // 大于一分钟小于一小时展示为分钟
        dateStr = Math.round((diff / minute)) + '分钟前'
    } else if (hour < diff && diff <= day) {            // 大于一小时小于一天展示为小时
        dateStr = Math.round((diff / hour)) + '小时前'
    } else if (day < diff && diff <= month) {           // 大于一天小于三十天展示为天
        dateStr = Math.round((diff / day)) + '天前'
    } else if(month < diff && diff <= year){            // 大于三十天展示为天小于一年展示为月
        dateStr = Math.round((diff / month)) + '月前'
    } else {                                            // 大于一年展示为年
        dateStr = Math.round((diff / year)) + '年前'
    }                                               
    return dateStr
}



/**
 * 判断浏览器内核
 * @returns string
 */
 function browser(){
    var u = navigator.userAgent
    if(u.indexOf('Trident')>-1)return 'IE内核'
    if(u.indexOf('Presto')>-1)return  'opera内核'
    if(u.indexOf('AppleWebkit')>-1)return  '苹果、谷歌内核'
    if(u.indexOf('Firefox')>-1)return  '火狐内核Gecko'
}
result = browser()



/**
 * 判断是移动端还是PC端
 * @returns String
 */
 function browserPc(){
    var ed = navigator.userAgent
    if(ed.indexOf('iPhone') > -1 || ed.indexOf('Android') > -1 || ed.indexOf('iPad') > -1) return '移动端'
    else return '电脑端'
}


/**
 * 判断是否是微信浏览器
 * @returns string
 */
 function browserWx(){
    if(navigator.userAgent.indexOf('MicroMessenger')>-1) return '微信浏览器'
    else return '不是微信浏览器'
}


/**
 * 获取标签非行内样式
 * @param {Object} Obj // 标签对象
 * @param {String} Attr // CSS属性值
 * @returns String
 */
 function getAttr(obj, attr) {
	let style;
    if (obj.currentStyle) {//当有这个属性的时候currentStyle
    	style = obj.currentStyle[attr]; //兼容IE 我测试的是ie5+
    } else {
        style = getComputedStyle(obj, false)[attr]; //主流浏览器
    }
      return style;
} 



/**
 * 获取随机颜色
 * @return string
 */

 function randomColor(){
    var arr = [1,2,3,4,5,6,7,8,9,0,'a','b','c','d','e','f']
    var max = arr.length-1
    var min = 0
    var one = arr[Math.floor(Math.random()*(max-min+1)+min)]
    var two = arr[Math.floor(Math.random() * (max-min+1)+min)]
    var three = arr[Math.floor(Math.random() * (max-min+1)+min)]
    var four = arr[Math.floor(Math.random() * (max-min+1)+min)]
    var five = arr[Math.floor(Math.random() * (max-min+1)+min)]
    var six = arr[Math.floor(Math.random() * (max-min+1)+min)]
    return '#'+one+two+three+four+five+six
}
/**
 * 
 */